#include<bits/stdc++.h>
using namespace std;
const int N=100005;
int t,n,m,l,v1,d[N],v[N],a[N],p[N],cnt;
int main(){
    freopen("detect.in","r",stdin);
    freopen("detect.out","w",stdout);
    cin>>t;
    while(t--){
        cnt=0;
        memset(d,0,sizeof d);
        memset(v,0,sizeof v);
        memset(a,0,sizeof a);
        cin>>n>>m>>l>>v1;
        for(int i=1;i<=n;i++)   cin>>d[i]>>v[i]>>a[i];
        for(int i=1;i<=m;i++)   cin>>p[i];
        for(int i=1;i<=n;i++){
            if(v[i]>v1) cnt++;
        }
        if(cnt>0)   cout<<cnt<<' '<<m-1<<endl;
        else    cout<<cnt<<' '<<m<<endl;
    }
    fclose(stdin);
    fclose(stdout);
    return 0;
}
